package struct
{
	import main.ClientConstants;
	
	public class RecommendPath extends StructBase
	{
		public var id:int;
		public var type:int;
		public var name:String;
		public var desc:String;
		public var info:Array;
		public var totalDays:Number;
		public var url:String;
		
		public function RecommendPath()
		{
		}
		
		public function initThis():void
		{
			var obj:Object = this._xmlLoaderManager.recommendPathXml.load("id",id);
			
			if(obj){
				this.id = obj.id;
				this.type = obj.type;
				this.name = obj.name;
				
				createInfo(obj.info);
				
				this.desc = obj.desc;
				this.totalDays = obj.totalDays;
				this.url = obj.url;
			}
		}
		
		private function createInfo(list:Array):void
		{
			var infoList:Array = [];
			for(var i:int = 0;i < list.length;i++){
				var partInfoList:Array = [];
				
				if(list[i] is String){
					var daliyList:Array = list[i].split("^");
					for(var j:int = 0;j < daliyList.length;j++){
						var itemList:Array = daliyList[j].split("@");
						var visitItem:*;
						if(itemList[1] == ClientConstants.VISIT_TYPE_SCENIC){
							visitItem = new Scenic;
							visitItem.init(_uri,_xmlLoaderManager);
							visitItem.id = itemList[0];
							visitItem.type = itemList[1];
							visitItem.initThis();
						}else if(itemList[1] == ClientConstants.VISIT_TYPE_EATING){
							visitItem = new Restaurant;
							visitItem.init(_uri,_xmlLoaderManager);
							visitItem.id = itemList[0];
							visitItem.type = itemList[1];
							visitItem.initThis();
						}else if(itemList[1] == ClientConstants.VISIT_TYPE_FUN){
							visitItem = new ScenicShop;
							visitItem.init(_uri,_xmlLoaderManager);
							visitItem.id = itemList[0];
							visitItem.type = itemList[1];
							visitItem.initThis();
						}else if(itemList[1] == ClientConstants.VISIT_TYPE_HOTEL){
							visitItem = new Hotel;
							visitItem.init(_uri,_xmlLoaderManager);
							visitItem.id = itemList[0];
							visitItem.type = itemList[1];
							visitItem.initThis();
						}
						partInfoList.push(visitItem);
					}
					infoList.push(partInfoList);
				}
			}
			this.info = infoList;
		}
		
		public function initList():void
		{
			createInfo(this.info);
			
			if(this.type == ClientConstants.PATH_TYPE_SELF){
				this.url = "";
			}
		}
		
		public function initWithData(obj:Object):void
		{
			if(obj){
				this.id = obj.id;
				this.type = obj.type;
				this.name = obj.name;
				
				createInfo(obj.info);
				
				this.desc = obj.desc;
				this.totalDays = obj.totalDays;
				this.url = _uri.getScenicImage("path/",obj.url);
			}
		}
	}
}